<template>
  <div>
    <div v-if="isShowQueryInput" style="text-align: right;">
      <el-input v-model="queryVal" size="small" placeholder="请输入内容" style="width: 190px; margin-right: 5px;" @keyup.enter.native="query(1, queryVal)" />
      <el-button type="primary" size="small" @click="query(1, queryVal)">查询</el-button>
    </div>
    <el-table
      ref="singleTable"
      :data="data"
      style="width: 100%"
      highlight-current-row
      @current-change="handleCurrentChange"
    >
      <slot />
    </el-table>
    <div v-if="selectedRow" style="margin-top: 20px">
      <el-button @click="setCurrent()">取消选择</el-button>
      <el-button @click="currentSelected()">确定</el-button>
    </div>
  </div>
</template>
<script>
export default {
  name: 'Filtertable',
  props: {
    data: {
      type: Array,
      default() {
        return []
      }
    },
    confirm: {
      type: String,
      default: '确定'
    },
    query: {
      type: Function,
      default: Function
    },
    isShowQueryInput: Boolean
  },
  data() {
    return {
      queryVal: '',
      selectedRow: ''
    }
  },
  methods: {
    handleCurrentChange(data) {
      // this.selectedRow = val
      if (!data) return
      const staffId = data.id
      const title = data.title
      this.$emit('currentSelected', staffId, title)
    },
    setCurrent(row) {
      this.$refs.singleTable.setCurrentRow(row)
    },
    currentSelected() {
      const data = this.selectedRow
      const staffId = data.id
      const title = data.title
      this.$emit('currentSelected', staffId, title)
      // bizorg_remove({ staffId, orgId }).then((res) => {
      // console.log(res)
      // })
    }
  }
}
</script>
